unit observacao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBClient, StdCtrls, Grids, DBGrids, Buttons;

type
  TFormObs = class(TForm)
    Label11: TLabel;
    cdsObs: TClientDataSet;
    cdsObsObs: TStringField;
    DataSource1: TDataSource;
    DBGridObs: TDBGrid;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure DBGridObsKeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormObs: TFormObs;

implementation
uses pedido, PedidoMesa;

{$R *.dfm}

procedure TFormObs.BitBtn1Click(Sender: TObject);
begin

cdsObs.First;
if assigned(FormPedido) then
   FormPedido.EditObs.Text := ''
else
   FormPedidoMesa.EditObs.Text := '';

while not cdsObs.Eof do
begin
    if Trim(cdsObsObs.AsString) <> '' then
    begin
       if assigned(FormPedido) then
          FormPedido.EditObs.Text := FormPedido.EditObs.Text + copy(uppercase(cdsObsObs.AsString)+StringOfChar(' ',20),1,20)
       else
          FormPedidoMesa.EditObs.Text := FormPedidoMesa.EditObs.Text + copy(uppercase(cdsObsObs.AsString)+StringOfChar(' ',20),1,20);
    end;

    cdsObs.Next;
end;


end;

procedure TFormObs.FormActivate(Sender: TObject);
var xpos : integer;
begin

cdsObs.DisableControls;
cdsObs.CreateDataSet;

cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;
cdsObs.Append;
cdsObs.Post;



cdsObs.EnableControls;

cdsObs.First;

xpos := 1;

if assigned(FormPedido) then
begin
    if Trim(FormPedido.EditObs.Text) <> '' then
    begin
        while xpos <= length(FormPedido.EditObs.Text)  do
        begin
            cdsObs.Edit;
            cdsObsObs.AsString := copy(FormPedido.EditObs.Text,xpos,20);
            xpos := xpos + 20;
            cdsObs.Post;
            cdsObs.Next;

        end;

    end;
end
else
begin
    if Trim(FormPedidoMesa.EditObs.Text) <> '' then
    begin
        while xpos <= length(FormPedidoMesa.EditObs.Text)  do
        begin
            cdsObs.Edit;
            cdsObsObs.AsString := copy(FormPedidoMesa.EditObs.Text,xpos,20);
            xpos := xpos + 20;
            cdsObs.Post;
            cdsObs.Next;

        end;

    end;
end;

cdsObs.First;



end;

procedure TFormObs.DBGridObsKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
begin
   cdsObsObs.AsString := uppercase(cdsObsObs.AsString);
   cdsObs.Next;
end;   

   
end;

procedure TFormObs.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = VK_Escape then
     self.close;
end;

end.
